<!--
* description: 车辆管理-销售出库
* author: ligy
* createdDate: 2020-11-17
-->
<template>
  <div class="app-container app-container-table">
    <one-table-template
      ref="multipleTable"
      :dynamic-buttons="tableButtons"
      :dynamic-components="tableComponents"
      :dynamic-api-config="dynamicApiConfig"
      :dynamic-table-cols="tableCols"
      :dynamic-form-fields="formField"
      :dynamic-is-show-select="false"
      :dynamic-is-init-table="true"
      :dynamic-is-column-drop="true"
      :is-set-default-brand="false"
      :dynamic-is-fix-choose="false"
      :dynamic-is-fix-index="false"
      :dynamic-api-style="'restful'"
    />
  </div>
</template>

<script>
import { oneTableWithViewTemplateMixins } from '@/components/mixins/oneTableWithViewTemplateMixins'
import OneTableTemplate from '@/components/templates/oneTable'
import api from '@/api/vehicleManagement'
import apis from '@/api/Lov'
export default {
  components: {
    OneTableTemplate
  },
  mixins: [oneTableWithViewTemplateMixins],
  data() {
    return {
      dynamicApiConfig: api.querySaleOutWarehouse,
      // 动态生成网格列
      tableCols: this.$ConfigCache.CacheConfig.cacheData[this.$route.path] &&
        this.$ConfigCache.CacheConfig.cacheData[this.$route.path].tableCols &&
        this.$ConfigCache.CacheConfig.cacheData[this.$route.path].tableCols
          .length > 0
        ? this.$ConfigCache.CacheConfig.cacheData[this.$route.path].tableCols
        : [
        // 操作
          {
            prop: '',
            label: '操作',
            align: 'center',
            fixed: false,
            isComponent: true,
            comps: [
              {
                compKey: 'propKey1',
                labelName: '出库',
                clickEvent: (index) => this.send(index),
                component: () => import('@/components/org/linkButton')
              }
            ]
          },
          {
            prop: 'saleOrderCode',
            label: '订单编号',
            align: 'center'
          },
          {
            prop: 'saleOrderSign',
            label: '订单标签',
            align: 'center'
          },
          {
            prop: 'salePlanCode',
            label: '销售计划号',
            align: 'center'
          },
          {
            prop: 'vin',
            label: 'VIN码',
            align: 'center'
          },
          {
            prop: 'pdiStatus',
            label: 'PDI状态',
            align: 'center'
          },
          {
            prop: 'pdiDate',
            label: 'PDI时间',
            align: 'center'
          },
          {
            prop: 'custName',
            label: '客户名称',
            align: 'center'
          },
          {
            prop: 'custTel',
            label: '客户电话',
            align: 'center'
          },
          {
            prop: 'custLxName',
            label: '联系人',
            align: 'center'
          },
          {
            prop: 'custLxPhone',
            label: '联系电话',
            align: 'center'
          },
          {
            prop: 'deliveryDlrShortName',
            label: '交付门店',
            align: 'center'
          },
          {
            prop: 'empName',
            label: '交付专员',
            align: 'center'
          }
        ],
      tableComponents: this.$ConfigCache.CacheConfig.cacheData[this.$route.path] &&
        this.$ConfigCache.CacheConfig.cacheData[this.$route.path]
          .tableComponents &&
        this.$ConfigCache.CacheConfig.cacheData[this.$route.path]
          .tableComponents.length > 0
        ? this.$ConfigCache.CacheConfig.cacheData[this.$route.path]
          .tableComponents
        : [
          {
            prop: 'releaseId',
            label: '主键ID',
            hidden: true,
            alwaysHidden: true
          },
          {
            prop: 'updateControlIdKc',
            label: '并发控制ID',
            hidden: true,
            alwaysHidden: true
          },
          {
            prop: 'updateControlIdSo',
            label: '订单并发字段',
            hidden: true,
            alwaysHidden: true
          },
          {
            prop: 'updateControlIdKc',
            label: '库存车并发字段',
            hidden: true,
            alwaysHidden: true
          },
          // 订单编号
          {
            compKey: 'compKey1',
            labelName: '订单编号：',
            codeField: 'saleOrderCode',
            component: () => import('@/components/org/commonInput'),
            type: 'inputText',
            isMust: true
          },
          // 订单标签
          {
            compKey: 'compKey2',
            labelName: '订单标签：',
            codeField: 'lookupValueCode',
            component: () => import('@/components/org/LookupValue'),
            lookuptype: 'VE1013',
            type: 'dropdownList',
            isMust: true
          },
          // 客户名称
          {
            compKey: 'compKey3',
            labelName: '客户名称：',
            codeField: 'custName',
            component: () => import('@/components/org/commonInput'),
            type: 'inputText',
            isMust: true
          },
          // 交付中心
          {
            compKey: 'compKey4',
            labelName: '交付门店：',
            codeField: 'deliveryDlrId',
            component: () => import('@/components/org/commonSelect'),
            oFields: 'deliveryDlrId,deliveryDlrShortName',
            customObj: {
              api: apis.listOfDeliveryStore
            },
            type: 'inputText',
            isMust: true
          },
          // VIN
          {
            compKey: 'compKey5',
            labelName: 'VIN：',
            codeField: 'vin',
            component: () => import('@/components/org/commonInput'),
            type: 'inputText',
            isMust: false
          },
          // PDI
          {
            compKey: 'compKey6',
            labelName: 'PDI状态：',
            codeField: 'pdiStatus',
            component: () => import('@/components/org/commonSelect'),
            oFields: 'pdiStatus,PsText',
            options: [
              { pdiStatus: '0', PsText: '未发起新车的PDI' },
              { pdiStatus: '1', PsText: '已完成新车的PDI' }
            ],
            type: 'inputText',
            isMust: false
          }
        ],
      tableButtons: [
        {
          conmpKey: 'btenKey1',
          type: 'primary',
          size: 'small',
          text: '查询',
          clickEvent: () => this.queryTable(1),
          position: 'right'
        },
        {
          conmpKey: 'btenKey2',
          type: '',
          size: 'small',
          text: '重置',
          clickEvent: () => this.reset(),
          position: 'right'
        }
      ],
      formField: this.$utils.getFormField(this, {
        saleOrderCode: '',
        lookupValueCode: '',
        custName: '',
        deliveryDlrId: '',
        vin: '',
        pdiStatus: ''
      })
    }
  },
  methods: {
    send(index) {
      this.$confirm('是否确定要出库', '提示', {
        type: 'warning'
      }).then(() => {
        const { saleOrderId, saleOrderDId, updateControlIdSo, updateControlIdKc, saleOrderCodeC, updateControlIdSod } = this.$refs['multipleTable'].list[index]
        const queryObj = {
        // 保存mutation
          type: 'mutation',
          // api配置
          apiConfig: api.updateOutWarehouse,
          // 条件/实体参数（变量），根据typeParam中的定义配置
          variables: { saleOrderId, saleOrderDId, updateControlIdSo, updateControlIdKc, saleOrderCodeC, updateControlIdSod }
        }
        var paramD = this.$getParams(queryObj)
        // 调用中台API方法（可复用）
        this.$requestAPI(paramD).then(response => {
          if (response.result === '1') {
            this.$message({
              message: response.msg
            })
            this.$nextTick(() => {
              this.$refs.multipleTable.queryTable(1)
            })
          } else {
            this.$message({
              message: response.msg
            })
          }
        }).catch(err => {
          console.log(err)
        })
      })
    }
  }
}
</script>

<style>
</style>
